//
//  String+kExtension.swift
//  kExtension
//
//  Created by 康凯 on 17/06/2017.
//  Copyright © 2017 康凯. All rights reserved.
//

import Foundation

extension String {
    // 使用下标截取字符串    例: "示例字符串"[0..<2] 结果是 "示例"
    subscript (r: Range<Int>) -> String {
        get {
            let startIndex = self.index(self.startIndex, offsetBy: r.lowerBound)
            let endIndex = self.index(self.startIndex, offsetBy: r.upperBound)
            
            return self[startIndex..<endIndex]
        }
    }
}

